class Solution(object):
    def minimumRefill(self, plants, capacityA, capacityB):
        n = len(plants)
        ans = 0
        c_A = 0
        c_B = 0
        for i in range(n // 2):
            c_A += plants[i]
            if c_A > capacityA:
                ans += 1
                c_A = plants[i]
            c_B += plants[n - 1 - i]
            if c_B > capacityB:
                ans += 1
                c_B = plants[n - 1 - i]
        if n % 2 == 0:
            return ans
        else:
            return int(ans + max(capacityA - c_A, capacityB - c_B) < plants[n // 2])
